<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>Title</title>
</head>
<body>

</body>
<script>
	// bind相较于call而言，接收的参数是一样的。
	// 不同点：bind返回函数，call执行函数
	Function.prototype.myBind = function(context){
		// console.log("myBind",this === fn);
		const _this = this;
		let arg = Array.from(arguments).slice(1);
		return function(){
			arg = arg.concat(Array.from(arguments)).join(",")
			if(context === undefined || context === null){
				context = window;
			}else if(typeof context !== "object" && typeof context !== "function"){
				context = new Object(context);
			}
			const fnName = Math.random().toString(36).slice(2);
			context[fnName] = _this;
			eval("context[fnName]("+arg+")")
			delete context[fnName];
		}
	}
	function fn(a,b,c,d,e,f){
		console.log(this,a,b,c,d,e,f);
	}
	fn.myBind({a:1,b:2},1,2,3,4)(5,6);
</script>
</html>